<!DOCTYPE html>
<html>

<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <title>修改房间</title>
    <link rel="stylesheet" href="layui/css/layui.css">
    <link rel="stylesheet" href="static/css/style.css">
    <link rel="stylesheet" href="layui/css/layuibtn.css">
</head>
<style>
    .roomType {
        display: block !important;
        width: 100%;
        border-color: #D2D2D2 !important;
        height: 38px;
        line-height: 1.3;
        border-width: 1px;
        border-style: solid;
        background-color: #fff;
        border-radius: 2px;
        padding-left: 10px;
    }
</style>

<body>
<div class="container">
    <fieldset class="layui-elem-field layui-field-title" style="margin-top: 20px;">
        <legend>修改代理</legend>
    </fieldset>

    <form class="layui-form" action="">
        <div class="layui-form-item">
            <label class="layui-form-label">商家id</label>
            <div class="layui-input-block">
                <input type="text" name="id" lay-verify="id" autocomplete="off" placeholder="请输入标题"
                       class="layui-input id" readonly="true" style="color: #ccc;">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">商家名称</label>
            <div class="layui-input-block">
                <input type="text" name="name" lay-verify="name" autocomplete="off" placeholder="请输入用户名"
                       class="layui-input name">
            </div>
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label">手机号</label>
            <div class="layui-input-block">
                <input type="text" name="phone" lay-verify="phone" autocomplete="off" placeholder="请输入手机号"
                       class="layui-input phone">
            </div>
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label">商家地址</label>
            <div class="layui-input-block">
                <input type="text" name="address" lay-verify="address" autocomplete="off" placeholder="请输入地址"
                       class="layui-input address">
            </div>
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label">抽成</label>
            <div class="layui-input-block">
                <input type="text" name="proportion" lay-verify="proportion" autocomplete="off" placeholder="请输入抽成"
                       class="layui-input proportion">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">分类</label>
            <div class="layui-input-block">
                <from class="layui-form">
                    <select name="typeid" lay-verify="typeid" id="typeid">
                        <option value="0">请选择一个分类</option>
                    </select>
                </from>
            </div>
        </div>
        <div class="layui-form-item">
            <button type="button" class="layui-btn" onclick="settijiao()">提交</button>
            <button type="button" class="layui-btn" id="quxiao">取消</button>
        </div>
    </form>
</div>

<script type="text/javascript" src="js/jquery.min.js"></script>
<script src="js/common.js"></script>
<script src="layui/layui.js"></script>
<script src="layer-v3.1.1/layer/mobile/layer.js"></script>
<script>
    var $
    var form

    //$(function() {
    layui.use(['element', 'layer', 'form'], function () {
        $ = layui.jquery;
        layer = layui.layer;
        form = layui.form; //只有执行了这一步，部分表单元素才会自动修饰成功
    });
    var dinId = getQueryString("roomId");
    $.ajax({
        type: "post",
        url: baseurl + "/dining/queryDiningOne",
        data: {
            id: dinId
        },
        success: function (data) {
            console.log(data)
            $(".id").val(data.data.id);
            $(".name").val(data.data.diningName);
            $(".address").val(data.data.address);
            $(".phone").val(data.data.phone);
            var xxx = parseInt(data.data.largeId);
            var xx = '';
            $.ajax({
                type: "post",
                url: baseurl + "/large/query",
                success: function (data) {

                    for (i = 0; i < data.data.length; i++) {
                        xx = xx + `
					        <option value="` + data.data[i].largeId + `">` + data.data[i].largeName + `</option>
                        `;
                    }
                    $("#typeid").html(`
				<option value="0">请选择一个分类</option>` + xx
                    );
                    $("#typeid").val(xxx);

                    form.render();
                }
            });

            $(".proportion").val(data.data.proportion);
        }
    });

    $("#quxiao").click(function () {
        parent.layer.closeAll();//关闭弹出层
        //window.parent.location.reload();
    })

    function settijiao() {
        $.ajax({
            type: "post",
            url: baseurl + "/subordinate/updates",
            data: {
                dinId: $(".id").val(),
                name: $(".name").val(),
                address: $(".address").val(),
                phone: $(".phone").val(),
                region: $("#typeid").val(),
                proportion: $(".proportion").val()
            },
            success: function (data) {
                console.log(data)
                if (data.meta.code == 200) {
                    layer.alert('修改成功', function () {
                        parent.layer.closeAll();//关闭弹出层
                    });
                } else {
                    layer.alert("修改失败" + data.meta.msg);
                }
            }
        })
    }
</script>
</body>

</html>